﻿using System;
using System.Data;
using System.Data.SqlClient;

namespace MyWeb.Data
{
    public class OrderController : SqlDataProvider
    {
        #region [Order_GetByAll]

        public DataTable Order_GetByAll()
        {
            return GetDataTable("sp_Order_GetByAll");
        }

        #endregion

        #region [Order_GetById]

        public DataTable Order_GetById(int id)
        {
            var p1 = new SqlParameter("@id", id);
            return GetDataTable("sp_Order_GetById", p1);
        }

        #endregion

        #region [Order_Insert]

        public void Order_Insert(OrderInfo order)
        {
            var p1 = new SqlParameter("@user_id", order.User_Id);
            var p2 = new SqlParameter("@TotalMoney", order.TotalMoney);
            var p3 = new SqlParameter("@Date", order.Date);
            var p4 = new SqlParameter("@Status", order.Status);
            ExecuteStoreProcedure("sp_Order_Insert", p1, p2, p3, p4);
        }

        #endregion

        #region [Order_Update]

        public void Order_Update(OrderInfo order)
        {
            var p0 = new SqlParameter("@id", order.Id);
            var p1 = new SqlParameter("@user_id", order.User_Id);
            var p2 = new SqlParameter("@TotalMoney", order.TotalMoney);
            var p3 = new SqlParameter("@Date", order.Date);
            var p4 = new SqlParameter("@Status", order.Status);
            ExecuteStoreProcedure("sp_Order_Update", p0, p1, p2, p3, p4);
        }

        #endregion

        #region [Order_Delete]

        public void Order_Delete(int id)
        {
            var p0 = new SqlParameter("@id", id);
            ExecuteStoreProcedure("sp_Order_Delete", p0);
        }

        #endregion

        #region [Order_GetId]

        public int Order_GetId()
        {
            return Int32.Parse(GetTopDataCell("[Order]", "Id", "Id"));
        }

        #endregion
    }
}